//
//  File.swift
//
//
//  Created by didi on 2022/9/13.
//

import SwiftHtml
import Vapor

public struct FileFieldTemplate: TemplateRepresentable {
    public var context: FileFieldContext

    public init(_ context: FileFieldContext) {
        self.context = context
    }

    @TagBuilder
    public func render(_ req: Request) -> Tag {
        LabelTemplate(context.label).render(req)

        Input()
            .type(.file)
            .key(context.key)
            .accept(context.accept)
            .class("field")
        if let error = context.error {
            Span(error)
                .class("error")
        }
    }
}
